<template>
	<view class="com-content">
		<block v-for="(obj,index) in list" :key="index">
			<!--聊天列表-->
			<view v-if="type==='group' && isPinned">
				<view class="com-box" @click="tomsg(obj.conversation.toAccount,obj.conversation.groupProfile.name,obj.conversation.type)" v-if="obj.conversation.isPinned">
					<!--群聊-置顶-->
					<view class="com-box-img">
						<view class="com-imgs">
							<block v-for="(item,ind) in obj.users" :key="ind">
								<image class="com-img" :src="item.img || $mAssetsPath.icon_mrtx" v-if="ind<9"></image>
							</block>
						</view>
						<view class="number" v-if="obj.conversation.unreadCount>0 && obj.conversation.unreadCount < 100">{{obj.conversation.unreadCount}}</view>
						<view class="number2" v-else-if="obj.conversation.unreadCount >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.conversation.groupProfile.name}}</view>
							<view class="time">{{obj.conversation.lastMessage.lastTime*1000 | formatDate }}</view>
						</view>
						<view class="bot">
							<view class="txt">{{obj.user.nickname}}：<rich-text class="txt2" :nodes="nodesFliter(obj.conversation.lastMessage.messageForShow)">
							</rich-text></view>
							<image class="icon_jy" :src="$mAssetsPath.icon_zhiding"></image>
							<image class="icon_jy" v-if="obj.conversation.groupProfile.selfInfo.messageRemindType === 'AcceptNotNotify'" :src="$mAssetsPath.icon_jingyin"></image>
						</view>
					</view>
				</view>
			</view>
			<view v-else-if="type==='group' && !isPinned">
				<view class="com-box" @click="tomsg(obj.conversation.toAccount,obj.conversation.groupProfile.name,obj.conversation.type)" v-if="!obj.conversation.isPinned">
					<!--群聊-置顶-->
					<view class="com-box-img">
						<view class="com-imgs">
							<block v-for="(item,ind) in obj.users" :key="ind">
								<image class="com-img" :src="item.img || $mAssetsPath.icon_mrtx" v-if="ind<9"></image>
							</block>
						</view>
						<view class="number" v-if="obj.conversation.unreadCount>0 && obj.conversation.unreadCount < 100">{{obj.conversation.unreadCount}}</view>
						<view class="number2" v-else-if="obj.conversation.unreadCount >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.conversation.groupProfile.name}}</view>
							<view class="time">{{obj.conversation.lastMessage.lastTime*1000 | formatDate }}</view>
						</view>
						<view class="bot">
							<view class="txt">{{obj.user.nickname}}：<rich-text class="txt2" :nodes="nodesFliter(obj.conversation.lastMessage.messageForShow)">
							</rich-text></view>
							<image class="icon_jy" v-if="obj.conversation.groupProfile.selfInfo.messageRemindType === 'AcceptNotNotify'" :src="$mAssetsPath.icon_jingyin"></image>
						</view>
					</view>
				</view>
			</view>
			<view v-else-if="type==='single' && isPinned">
				<!--单聊-->
				<view class="com-box" @click="tomsg(obj.conversation.toAccount,obj.user.nickname,obj.conversation.type)" v-if="obj.conversation.isPinned">
					<view class="com-imgs">
						<image class="com-img2" :src="obj.user.img || $mAssetsPath.icon_mrtx"></image>
						<view class="number"
							v-if="obj.conversation.unreadCount>0 && obj.conversation.unreadCount < 100">
							{{obj.conversation.unreadCount}}</view>
						<view class="number2" v-else-if="obj.conversation.unreadCount >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.user.nickname}}</view>
							<view class="time">{{obj.conversation.lastMessage.lastTime*1000 | formatDate }}</view>
						</view>
						<view class="bot">
							<rich-text class="txt" :nodes="nodesFliter(obj.conversation.lastMessage.messageForShow)">
							</rich-text>
							<image class="icon_jy" :src="$mAssetsPath.icon_zhiding"></image>
						</view>
					</view>	
				</view>
			</view>
			<view v-else-if="type==='single' && !isPinned">
				<!--单聊-->
				<view class="com-box" @click="tomsg(obj.conversation.toAccount,obj.user.nickname,obj.conversation.type)" v-if="!obj.conversation.isPinned">
					<view class="com-imgs">
						<image class="com-img2" :src="obj.user.img || $mAssetsPath.icon_mrtx"></image>
						<view class="number"
							v-if="obj.conversation.unreadCount>0 && obj.conversation.unreadCount < 100">
							{{obj.conversation.unreadCount}}</view>
						<view class="number2" v-else-if="obj.conversation.unreadCount >= 100">99+</view>
					</view>
					<view class="com-box-r">
						<view class="top">
							<view class="name">{{obj.user.nickname}}</view>
							<view class="time">{{obj.conversation.lastMessage.lastTime*1000 | formatDate }}</view>
						</view>
						<view class="bot">
							<rich-text class="txt" :nodes="nodesFliter(obj.conversation.lastMessage.messageForShow)">
							</rich-text>
						</view>
					</view>	
				</view>
			</view>
			
			
			<view class="com-box" @click="tosysmsg()" v-else-if="type==='system'">
				<!-- 系统 -->
				<view class="com-imgs">
					<!-- <block v-for="(item,i) in obj.head" :key="i">
							<image class="com-img2" :src="$mAssetsPath.icon_sys" v-if="i<1"></image>
						</block> -->
					<image class="com-img2" :src="$mAssetsPath.icon_sys"></image>
					<view class="number" v-if="obj.msg_no_count > 0 && obj.msg_no_count < 100">{{obj.msg_no_count}}
					</view>
					<view class="number2" v-else-if="obj.msg_no_count >= 100">99+</view>
				</view>
				<view class="com-box-r">
					<view class="top">
						<view class="name">系统通知</view>
						<view class="time">{{timeFliter(obj.create_time)}}</view>
					</view>
					<view class="txt">{{obj.data.msg}}</view>
				</view>
			</view>

		</block>
	</view>
</template>

<script>
	export default {
		name: "com-top",
		components: {},
		props: {
			isPinned:{
				type:Boolean,
				default:false
			},
			list: {
				type: Array,
				default () {
					return []
				}
			},
			type: {
				type: String,
				default: 'group'
			}
		},
		data() {
			return {

			}
		},
		methods: {
			//时间过滤
			timeFliter(timer) {
				let timeData = new Date(timer * 1000)
				let str = this.$commen.dateTimeFliter(timeData)
				return str
			},
			//聊天的节点加上外层的div
			nodesFliter(str) {
				let nodeStr = '<div style="align-items: center;word-wrap:break-word;">' + str + '</div>'
				return nodeStr
			},
			tomsg(id, name, type) {
				this.$emit('tomsg', id, name, type)
			},
			tosysmsg() {
				this.$emit('tosysmsg')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.icon_jy{
		width: 36rpx;
		height: 36rpx;
	}
	.com-content {
		display: flex;
		flex-direction: column;
		width: 100%;
	}

	.com-box {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 30rpx 0 30rpx;

		.com-box-img {
			width: 96rpx;
			height: 96rpx;
			margin-right: 20rpx;
			position: relative;

			.com-imgs {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-wrap: wrap;
				width: 96rpx;
				height: 96rpx;
				border-radius: 10rpx;
				overflow: hidden;
				padding: 2rpx;
				background: $uni-but-bg-color-b;

				.com-img {
					width: 28rpx;
					height: 28rpx;
					margin: 0 4rpx 4rpx 0;
				}

				.com-img:nth-of-type(3n) {
					margin: 0 0 4rpx 0;
				}
			}

			.number {
				width: 32rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}

			.number2 {
				width: 52rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}
		}

		.com-imgs {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-wrap: wrap;
			width: 96rpx;
			height: 96rpx;
			margin-right: 20rpx;
			border-radius: 48rpx;
			background: $uni-but-bg-color-b;
			position: relative;

			.com-img2 {
				width: 96rpx;
				height: 96rpx;
				border-radius: 10rpx;
			}

			.number {
				width: 32rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}
			
			.number2 {
				width: 52rpx;
				height: 32rpx;
				border-radius: 16rpx;
				background: #FF5454;
				font-size: 18rpx;
				line-height: 30rpx;
				text-align: center;
				color: $font-color-w;
				position: absolute;
				right: -16rpx;
				top: -16rpx;
			}
		}

		.com-box-r {
			width: calc(100% - 116rpx);

			.top {
				display: flex;
				justify-content: space-between;

				.name {
					font-size: 32rpx;
					font-weight: 400;
					color: $font-color-3;
					margin-bottom: 10rpx;
				}

				.time {
					font-size: 24rpx;
					font-weight: 400;
					color: $font-color-b;
				}
			}
			.bot{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.txt {
					width: calc(100% - 40rpx);
					display: flex;
					align-items: center;
					font-size: 28rpx;
					font-weight: 400;
					color: $font-color-9;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					.text2{
						display:flex;
						align-items: center;
					}
				}
			}

			.txt {
				width: calc(100% - 40rpx);
				display: flex;
				align-items: center;
				font-size: 28rpx;
				font-weight: 400;
				color: $font-color-9;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				.text2{
					display:flex;
					align-items: center;
				}
			}
		}

	}
</style>
